package A1_二叉树;

public class LC_101对称二叉树 {
    public static class TreeNode{
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(){}
        TreeNode(int val){
            this.val=val;
        }
        TreeNode(int val, TreeNode left, TreeNode right){
            this.val=val;
            this.left=left;
            this.right=right;
        }
    }
    public boolean isSymmetric(TreeNode root) {
        return compare(root.left,root.right);
    }
    public static boolean compare(TreeNode left,TreeNode right) {
        if(left!=null && right==null)
            return false;
        else if(left==null && right!=null)
            return false;
        else if(left==null && right==null)
            return true;
        else if(left.val!=right.val)
            return false;
        boolean outside=compare(left.left,right.right);
        boolean inside=compare(left.right,right.left);
        return outside && inside;
    }
}


